<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>">
    <meta charset="utf-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="js/layui/css/layui.css"  media="all">
</head>
<body>
<div style="margin-left: 10%">
    <div  style="padding-left: 80px">
        <div class="layui-btn">添加订单</div>
        <button class="layui-btn" style="float: right;margin-right: 50%" data-type="reload" id="sousuo">搜索</button>
        <div class="layui-inline" style="text-align: center;float:right">
            <input class="layui-input" name="keyword" placeholder="搜索订单id" id="demoReload" autocomplete="off">
        </div>
    </div>
    <table  class="layui-table" id="test1" lay-filter="demo"></table>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="downLine">确认订单</a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">订单详情</a>
   <%-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reserve">预投列表</a>--%>
</script>


<script src="js/layui/layui.js" charset="utf-8"></script>
<script>

    layui.use(['table' ,'laypage'], function(){
        var table = layui.table;
        var $ = layui.$;
        table.render({
            elem: '#test1'
            ,height: 500
            ,url: 'order/findAll' //数据接口  请求自动拼接参数page=1&limit=10
            ,limit:2//每页显示条数
            ,cols: [[ //表头
                // {type:'checkbox', fixed: 'left'}
                {field: 'orderId', title: 'ID', width:80, sort: true,align:'center'}
                ,{field: 'orderNo', title: '订单号', width:200}
                ,{field: 'receiver', title: '收货人', align:'center', width:80}
                ,{field: 'phone', title: '电话',align:'center',  width:150}
                ,{field: 'createTime', title: '创建时间',align:'center',  width: 120}
                ,{field: 'status', title: '支付状态', width:220, align:'center', toolbar: '#barDemo'}

            ]]
            ,page:true//开启分页
        });

        //  监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){//项目详情按钮
                layer.open({
                    title: false,//弹出层的title不显示
                    type: 2,
                    area: ['80%', '400px'],
                    content: 'order/orderdetail' + data.id
                });
            } else if(obj.event === 'reserve'){//预投列表按钮
                layer.open({
                    title: false,//弹出层的title不显示
                    type: 2,
                    area: ['70%', '800px'],
                    content: 'reserve/toReserve.do?itemId=' + data.id

                });
            } else if(obj.event === 'downLine'){//项目下线按钮
                layer.confirm('确定订单?', function(index){
                    $.ajax({
                        url: "order/findById?orderid="+data.id,    //后台数据请求地址
                        type:"GET",
                        datatype:"json",
                        async:false,
                        success:function(data){
                            if(data.statusCode==300){
                                layer.alert("失败")
                            }
                        }
                    })
                    layer.close(index);
                    table.reload('test1',{
                        page: {
                            curr: 1  //重载后显示页码
                        }
                    });
                });
            }
        });
        //搜索按钮事件
        $('#sousuo').on('click',function () {
            var inputVal = $('.layui-input').val();//获取input标签输入内容
            //表格重载
            table.reload('test1', {
                where: {
                    title : inputVal  //携带参数 或变更参数
                }
                ,page: {
                    curr: 1  //重载后显示页码
                }
            })
        });
    })

</script>

</body>
</html>